package com.zhongfl.crm.api.view;

import com.github.pagehelper.PageInfo;
import com.heptagram.lixiao.api.LiXiaoService;
import com.heptagram.lixiao.bean.response.opportunity.LXOpportunityResponse;
import com.heptagram.lixiao.common.exception.LiXiaoErrorException;
import com.zhongfl.crm.lixiao.batch.service.OrderSyncFromLX2BossService;
import com.zhongfl.crm.model.crm.StaffExt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import tech.heptagram.core.common.rest.ResponseResult;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * @author: 蜻蜓
 * @date: 2019-04-02 21:45:19
 */
@RestController
@RequestMapping("/api/view/tools")
@Slf4j
public class ToolsController {

    @Resource
    private LiXiaoService liXiaoService;

    @Resource
    private OrderSyncFromLX2BossService orderSyncFromLX2BossService;

    @GetMapping("/synchronize/{id}")
    public ResponseResult<PageInfo<StaffExt>> findUserList(@PathVariable Long id) throws ParseException, LiXiaoErrorException {
        LXOpportunityResponse response = liXiaoService.getOpportunityService().findOpportunityByOrderId(id);
        orderSyncFromLX2BossService.syncSingleLxOrder2Boss(response.getData());
        return new ResponseResult("同步成功");
    }


}
